﻿using Lypshare.Net.Server.Service;
using System.Net;
using System;

namespace Lypshare.Net.Client
{
	/// <summary>
	/// Interface network session.
	/// </summary>
    public interface INetworkSession : IAccessServiceCallback
    {
        // --------------------------------------------------------
        // Class Events
        // --------------------------------------------------------


        /// <summary>
        /// Occurs when client joined.
        /// </summary>
        event Action<INetworkSession, ConnectionEventArgs> ClientJoined;


        /// <summary>
        /// Occurs when client left.
        /// </summary>
        event Action<INetworkSession, ConnectionEventArgs> ClientLeft;


        /// <summary>
        /// Occurs when data received.
        /// </summary>
        event Action<INetworkSession, ConnectionDataEventArgs> DataReceived;


        /// <summary>
        /// Occurs when data sent.
        /// </summary>
        event Action<INetworkSession, ConnectionDataEventArgs> DataSent;
		
		
		/// <summary>
		/// Occurs when closed.
		/// </summary>
		event Action<INetworkSession> Closed;
            

        // --------------------------------------------------------
        // Interface Properties
        // --------------------------------------------------------
		
		
		/// <summary>
		/// Gets the identifier.
		/// </summary>
		/// <value>
		/// The identifier.
		/// </value>
		int Id { get; }
		
		
		/// <summary>
		/// Gets the address.
		/// </summary>
		/// <value>
		/// The address.
		/// </value>
		IPAddress Address { get; }
		

        /// <summary>
        /// Gets the connections.
        /// </summary>
        /// <value>
        /// The connections.
        /// </value>
        IConnection[] Connections { get; }
		
		
		/// <summary>
		/// Gets a value indicating whether this instance is authed.
		/// </summary>
		/// <value>
		/// <c>true</c> if this instance is authed; otherwise, <c>false</c>.
		/// </value>
		bool IsAuthed { get; }
		
		
		/// <summary>
		/// Gets a value indicating whether this instance has scope.
		/// </summary>
		/// <value>
		/// <c>true</c> if this instance has scope; otherwise, <c>false</c>.
		/// </value>
		bool HasScope { get; }
		
		
        /// <summary>
        /// Gets the scope.
        /// </summary>
        /// <value>
        /// The scope.
        /// </value>
        String Scope { get; }


        /// <summary>
        /// Gets a value indicating whether this instance is active.
        /// </summary>
        /// <value>
        /// <c>true</c> if this instance is active; otherwise, <c>false</c>.
        /// </value>
        bool IsActive { get; }


        // --------------------------------------------------------
        // Interface Functions
        // --------------------------------------------------------


        /// <summary>
        /// Gets the connection.
        /// </summary>
        /// <returns>
        /// The connection.
        /// </returns>
        /// <param name='clientId'>
        /// Client identifier.
        /// </param>
        IConnection GetConnection(int clientId);
		
		
		/// <summary>
		/// Auth the specified username and password.
		/// </summary>
		/// <param name='username'>
		/// If set to <c>true</c> username.
		/// </param>
		/// <param name='password'>
		/// If set to <c>true</c> password.
		/// </param>
		bool Auth(String username, String password);
		
		
		/// <summary>
        /// Join the specified scope.
        /// </summary>
        /// <param name='scope'>
        /// Scope.
        /// </param>
        void Join(String scope);
		
		
		/// <summary>
		/// Synchronize with the specified connection and port.
		/// </summary>
		/// <param name='connection'>
		/// Connection.
		/// </param>
		/// <param name='port'>
		/// Port.
		/// </param>
		int Synchronize(IConnection connection, int port);
	

        /// <summary>
        /// Shutdown this instance.
        /// </summary>
        void Shutdown();

    } // interface INetworkSession
} // namespace Lypshare.Net.Client